package com.xiaoma.future.completableFuture_start;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
public class ThenAccepetBoth {

    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(10);
        CompletableFuture<Double> cf = CompletableFuture.supplyAsync(() -> {
            log.info("开始查询北京->广州的飞机票价格");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 2000.0;
        }, pool);
        CompletableFuture<Double> cf1 = CompletableFuture.supplyAsync(() -> {
            log.info("开始查询广州->北京的飞机票价格");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 2000.0;
        }, pool);

        //没有返回值
        cf.thenAcceptBoth(cf1, (p1, p2) -> {
            log.info("计算往返票价" + (p1 + p2));
        });

        pool.shutdown();

    }


}
